﻿using System;
using Newtonsoft.Json;
namespace test
{
    class InterClass
    {
        static void Main(string[] args)
        {

            Messenger messenger = new Messenger();
            Stock stock = new Stock(messenger);
            System.Console.WriteLine("1------");
            stock.Price = 10;
            System.Console.WriteLine("2------");
            stock.Price = 20;
            System.Console.WriteLine(JsonConvert.SerializeObject(stock));
        }
    }

    class Messenger
    {
        public void alert() => System.Console.WriteLine("price属性变化");
    }
    class Stock
    {
        Messenger messenger;
        private int? _price;

        public int? Price
        {
            get { return _price; }
            // set { _price = value; }
            set
            {
                if (_price != value)
                {
                    _price = value;
                    messenger.alert();
                }
            }
        }
        public Stock(Messenger messenger)
        {
            this.messenger = messenger;
        }

    }
}